// components/titlebar.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    backUrl: String,
    titleText: String,
    showBack: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    statusBarHeight: 0,
    navigationBarH: 0,
  },
  ready() {
    let systemInfo = wx.getSystemInfoSync()
    let menuButtonBoundingClientRect = wx.getMenuButtonBoundingClientRect()
    this.setData({
      statusBarHeight: systemInfo.statusBarHeight,
      navigationBarH: menuButtonBoundingClientRect.height + (menuButtonBoundingClientRect.top - systemInfo.statusBarHeight) * 2
    })
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //返回上一个页面
    back() {
      console.log('返回地址：', this.properties.backUrl)
      if(this.properties.backUrl){
        wx.redirectTo({ url: this.properties.backUrl })
      } else {
        wx.navigateBack({ //返回
          delta: 1,
          fail(err) {
            wx.redirectTo({ url: '/pages/index/index' })
          }
        })
      }
    }
  }
})